<?php

namespace App\Http\Controllers\Admin;

use App\Models\Depart;

class DepartController extends BaseController
{

    public function __construct(Depart $depart)
    {
        parent::__construct();
        $this->depart = $depart;
    }

    public function getIndex()
    {
        $rows = $this->depart->getDepartList();
        return view('admin.depart.index', compact('rows'));
    }

    public function getAdd()
    {
        $departs = apiCurl('regDeparts');
        return view('admin.depart.add',compact('departs'));
    }

    public function postAdd()
    {
        $res = $this->depart->addDepart(request());
        return redirect()->back()->with('message', $res)->withInput();
    }

    public function getEdit()
    {
        $res = $this->depart->getDepartInfoById(request('id'));
        $departs = apiCurl('regDeparts');
        return view('admin.depart.edit',compact('res','departs'));
    }

    public function postEdit()
    {
        $res = $this->depart->editDepart(request());
        return redirect()->back()->with('message', $res)->withInput();
    }
    
    public function getDel()
    {
        $res = $this->depart->delDepart(request());
        return ajax_return($res);
    }

}